set seed 21112023

***THIS CODE WILL GENERATE BOOTSTRAP SAMPLES, WHICH WE SAVE, THEN ESTIMATE IN A LATER DO FILE
**ALLOWS US TO RUN ESTIMATION ON MULTIPLE COMPUTERS (WHILE FIXING SEED)
local bsamplesize = 100


****************** Revenue: new kl *********************************************

**************all obs
use  "$working/ProdR_new_kl_sampleFS", clear
merge 1:1 co_code1 year using "$working/ProdR_new_kl_sampleSS_allobs"

generate samples = 1 if _merge==3 | _merge==1 // Does not make sense to stratify on one observation - keep it group sample basically
replace samples = 2 if _merge==2
drop _merge

merge 1:m co_code1 year using "$working/ProdR_new_kl_sampleFS_prod"
drop _merge

save "$working/sample_new_kl_allobs", replace

forvalues bs = 1(1)`bsamplesize' {
	clear
	***Grab bootstrap samples
	use "$working/sample_new_kl_allobs"
	bsample,  strata(samples) cluster(co_code1) idcluster(bs_co_code1)
	save "$BS_fold_old/record/Rkl/allobs/bssample_`bs'", replace
}


**************Decomposition Sample
use  "$working/ProdR_new_kl_sampleFS", clear
merge 1:1 co_code1 year using "$working/ProdR_new_kl_sampleSS"

generate samples = 1 if _merge==3
replace samples = 2 if _merge==1
drop _merge

merge 1:m co_code1 year using "$working/ProdR_new_kl_sampleFS_prod"
drop _merge

save "$working/sample_new_kl", replace

forvalues bs = 1(1)`bsamplesize' {
	clear
	***Grab bootstrap samples
	use "$working/sample_new_kl"
	bsample,  strata(samples) cluster(co_code1) idcluster(bs_co_code1)
	save "$BS_fold_old/record/Rkl/base/bssample_`bs'", replace
}
